package com.hmall.controller;

import com.hmall.common.dto.FilterDTO;
import com.hmall.common.vo.PageVo;
import com.hmall.service.EsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author leslie
 * @create 2023/9/1 0001 17:18
 */
@RestController
@RequestMapping("/search")
public class EsController {
    @Autowired
    private EsService esService;

    @GetMapping("/insert")
    public void saveBulk(){
        esService.insertBulkData();
    }
    @GetMapping("/suggestion")
    public List<String> autoCompletion(@RequestParam("key") String key){
        List<String> suggestions = esService.autoCompletion(key);
        return suggestions;
    }
    @PostMapping("/filters")
    public Map<String,List<String>> filterSomething(@RequestBody FilterDTO filterDTO){
        Map<String,List<String>> filters = esService.filterSomething(filterDTO);
        return filters;
    }
    @PostMapping("/list")
    public PageVo list(@RequestBody FilterDTO filterDTO){
        PageVo pageVo = esService.list(filterDTO);
        return pageVo;
    }

}
